Documentation for Users  2.1.2
Perception Toolbox for Virtual Reality (PTVR) Manual
reticle_test_angular_size.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 """
3 ...\PTVR_Researchers\Python_Scripts\Demos\Pointing\
4  reticle_test_angular_size.py
5 
6 (see also ...\PTVR_Researchers\Python_Scripts\Demos\Objects\angular_size_of_object.py )
7 
8 Goal: show how to specify the angular size of a reticle and
9  check this angular value against visual objects.
10 
11 1st test: the angular size of the two objects is 2 deg of visual angle,
12  because the cube's size is set to 0.04 m at 1.15 m which
13  mathematically induces a 2 deg angular size.
14 
15 2nd test: the reticle, whose cursor cone diameter is set to 2 deg,
16  is thus visually superimposed with the 2 deg-diameter sphere.
17 
18 Note 1: When visually controlling angular values, remember that
19  angular values are accurate only when the eyes lie
20  close to the current Coordinate System's origin. Move your head if it
21  is not the case, you can use the Gizmo below your feet: if your head is
22  aligned with the green axis (Y), i.e. just above the CS' origin,
23  it will be fine.
24 
25 
26 Note 2: In this demo, the distance between head and reticle is intentionnally
27  constant and smaller than the distance between head and object.
28  Make sure your head is close to the CS's origin, otherwise the
29  reticle will disappear within the objects if your head is too close
30  to the objects.
31 
32 Note 3: The reticle belongs to the PTVR category called "flat cursors".
33 """
34 
35 from PTVR.Visual import The3DWorld
36 from PTVR.Stimuli.Scenes import VisualScene
37 from PTVR.Stimuli.Objects import Sphere, Cube, Gizmo
38 import PTVR.Stimuli.Color as color
39 import numpy as np
40 from PTVR.Pointing.PointingCursor import *
42 from PTVR.SystemUtils import LaunchThe3DWorld
43 import PTVR.Tools as tools
44 
45 # =============================================================================
46 # PARAMETERS #
47 # =============================================================================
48 
49 
50 
51 my_reticle_diameter_deg = 2 # diameter: 2 degrees
52 
53 my_contingency = ImageContingency.HEADSET
54 
55 my_eye_w_reticle = "both" # "right" or "left" or "both"
56 
57 
61 sphere_diameter_in_deg = 2 # 2
62 sphere_radial_distance_in_m = 1.15 # 1.15
63 
64 # Calculate size (in meters) from visual angle and viewing distance.
65 # Calculation below returns 0.04 m for sphere_diameter_in_m
66 sphere_diameter_in_m = \
67  tools.visual_angle_to_size_on_perpendicular_plane (
68  visual_angle_of_centered_object_in_deg = sphere_diameter_in_deg,
69  viewing_distance_in_m = sphere_radial_distance_in_m )
70 
71 # cube with size specified directly in meters
72 # to correspond to the angular calculation above
73 cube_size_in_m = 0.04
74 cube_radial_distance_in_m = 1.15
75 
76 # =============================================================================
77 # END PARAMETERS #
78 # =============================================================================
79 
80 # the simplest experiment
81 my_world = The3DWorld ()
82 def main():
83  my_scene = VisualScene ()
84 
85  # Gizmo at the origin of the Global Coordinate System
86  my_gizmo = Gizmo ( )
87  my_scene.place (my_gizmo, my_world)
88 
89  my_world.translate_coordinate_system_along_global ( np.array([0, 1.2, 0]))
90 
91  # internally create a PNG file to create an image
92  reticle_2D_image = RG.ReticleImageFromDrawing ( )
93  # reticle_2D_image.Show() # uncomment this line to show the image of the
94  # reticle in a new window of your PC
95 
96  head_reticle_distance = sphere_radial_distance_in_m - (5*sphere_diameter_in_m)
97 
98  my_reticle = ImageToContingentCursor (
99  image = reticle_2D_image,
100  eye_with_contingent_cursor = my_eye_w_reticle,
101  is_distance_constant = True,
102  constant_distance = head_reticle_distance,
103  size_in_degrees= [my_reticle_diameter_deg, my_reticle_diameter_deg] )
104 
105  my_scene.place_contingent_cursor (my_reticle)
106 
107 
109  my_sphere = Sphere ( size_in_meters = sphere_diameter_in_m )
110  my_sphere.set_perimetric_coordinates (eccentricity = 1, halfMeridian = 180,
111  radialDistance = sphere_radial_distance_in_m)
112  my_scene.place ( my_sphere, my_world)
113 
114  # cube
115  my_cube = Cube ( size_in_meters = cube_size_in_m )
116  my_cube.set_perimetric_coordinates (eccentricity = 1, halfMeridian = 0,
117  radialDistance = cube_radial_distance_in_m)
118  my_scene.place ( my_cube, my_world)
119 
120  my_world.add_scene (my_scene)
121  my_world.write ()
122 
123 if __name__ == "__main__":
124  main()
125  LaunchThe3DWorld() # Launch the Experiment with PTVR.
def LaunchThe3DWorld(jsonFileCategory="Externals")
Definition: SystemUtils.py:182